package cn.cvs.service.impl;

import cn.cvs.dao.SupplierMapper;
import cn.cvs.pojo.Supplier;
import cn.cvs.service.SupplierService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SupplierServiceImpl implements SupplierService {
    @Resource
    SupplierMapper supplierMapper;

    @Override
    public List<Supplier> querySupplies(String supCode, String supName, Integer pageNo, Integer pageSize) {
        List<Supplier> suppliers = supplierMapper.queryByPage(supCode, supName, (pageNo-1)*pageSize, pageSize);
        return suppliers;
    }

    @Override
    public int queryCount(String supCode, String supName) {
        int count = supplierMapper.queryCount(supCode, supName);
        return count;
    }

    @Transactional(rollbackFor = {Exception.class})
    @Override
    public int addSupplier(Supplier supplier) {
        int add = supplierMapper.add(supplier);
        return add;
    }

    @Override
    public Supplier queryById(Integer id) {
        Supplier supplier = supplierMapper.queryById(id);
        System.out.println(supplier);
        return supplier;
    }

    @Transactional(rollbackFor = {Exception.class})
    @Override
    public int update(Supplier supplier) {
        int i = supplierMapper.update1(supplier);
        return i;
    }
}
